package com.xiaolun;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author 硕鼠
 * @Date 2020/6/13 18:16
 * @Version 1.0
 * @Description 文件说明
 */
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("login请求进行来了");
        //获取前端请求的参数
        String username = req.getParameter("username");
        System.out.println("username--------->" + username);
        if (username.equals("admin")) {
            req.getSession().setAttribute("USER_SESSION", req.getSession().getId());
            resp.sendRedirect("/s1/sys/success.jsp");
        } else {
            resp.sendRedirect("/s1/error.jsp");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
